home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WQUERY.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  31.6 KB  |  973 lines

  1.  
  2. #ifndef _WQUERY_HPP_INCLUDED
  3. #define _WQUERY_HPP_INCLUDED
  4.  
  5. //-----------------------------------------------------------------------
  6. //
  7. // SQL Query object.
  8. //
  9. // The query object is patterned on the ODBC model.  The simplest way
  10. // to use it is as follows:
  11. //
  12. //     WQuery query;
  13. //
  14. //     query.Create( &transObject );
  15. //     query.SetSQLStatement( "select * from table" );
  16. //
  17. //     if( query.Open() ){
  18. //         query.Close();
  19. //     }
  20. //
  21. // The query object will only work when attached to a transaction object.
  22. // The transaction object must be connected to a database for most of
  23. // the methods to work.
  24. //
  25. //-----------------------------------------------------------------------
  26.  
  27. /*************************************************************************
  28.  *
  29.  *   Events:
  30.  *
  31.  *       AdjustCursor --
  32.  *
  33.  *       BeginFetchData --
  34.  *
  35.  *       BeginMoveCursor --
  36.  *
  37.  *       DatabaseError --
  38.  *
  39.  *       FetchData --
  40.  *
  41.  *       MoveCursor --
  42.  *
  43.  *       QueryBusy --
  44.  *
  45.  *       QueryClose --
  46.  *
  47.  *       QueryOpen --
  48.  *
  49.  *       QueryPrepare --
  50.  *
  51.  *       ValidateData --
  52.  *
  53.  ************************************************************************/
  54.  
  55. #ifndef _WDATASRC_HPP_INCLUDED
  56. #include "wdatasrc.hpp"
  57. #endif
  58. #ifndef _WDATAERR_HPP_INCLUDED
  59. #include "wdataerr.hpp"
  60. #endif
  61.  
  62. class WTransaction;
  63. class WQuery;
  64.  
  65. //
  66. // BindPolicy
  67. //
  68. //    Determines the policy the query object uses to bind the various
  69. //    columns.  The policy applies to columns that are not explicitly
  70. //    bound by the user or by any bound controls:
  71. //
  72. //      All     -- Bind all columns below a size threshhold
  73. //      Minimal -- If column "n" is bound, make sure columns 1 to n-1 are
  74. //                 bound.
  75. //      None    -- Do not do any default binding.
  76.  
  77. enum WQueryBindPolicy {
  78.     WQBPAll,    
  79.     WQBPMinimal,
  80.     WQBPNone
  81. };
  82.  
  83. //
  84. // UpdatePolicy
  85. //
  86. //    This policy determines the type of action to perform an update.
  87. //
  88. //    Auto       -- The query object determines which type to use.
  89. //    Direct     -- Directly updates the current row by using driver specific
  90. //                  functions if it's supported. i.e. in ODBC, SQLSetPos()
  91. //    Cursor     -- Open another query to execute a statement of type
  92. //                  UPDATE .... SET .... WHERE CURRENT OF <cursorname>
  93. //                  if it's supported.
  94. //    UserDefine -- The user defines an event handler for the ValidateData
  95. //                  event and writes their own code to perform the update.
  96. //
  97.  
  98. enum WQueryUpdatePolicy {
  99.     WQUPAuto,
  100.     WQUPDirect,
  101.     WQUPCursor,
  102.     WQUPUserDefine
  103. };
  104.  
  105. enum WQueryCursorType {
  106.     WQCTForwardOnly = SQL_CURSOR_FORWARD_ONLY,
  107.     WQCTKeysetDriven = SQL_CURSOR_KEYSET_DRIVEN,
  108.     WQCTDynamic = SQL_CURSOR_DYNAMIC,
  109.     WQCTStatic = SQL_CURSOR_STATIC
  110. };
  111.  
  112. enum WQueryConcurrencyLevel {
  113.     WQCLReadOnly = SQL_CONCUR_READ_ONLY,
  114.     WQCLLock = SQL_CONCUR_LOCK,
  115.     WQCLOptimisticByRowVer = SQL_CONCUR_ROWVER,
  116.     WQCLOptimisticByValues = SQL_CONCUR_VALUES
  117. };
  118.  
  119. enum WQueryParameterType {
  120.     WQPTInput = SQL_PARAM_INPUT,
  121.     WQPTInputOutput = SQL_PARAM_INPUT_OUTPUT,
  122.     WQPTOutput = SQL_PARAM_OUTPUT
  123. };
  124.  
  125. enum WQOption {
  126.  
  127.     // These are defined by ODBC
  128.  
  129.     WQOCursorType = SQL_CURSOR_TYPE,
  130.     WQORowsetSize = SQL_ROWSET_SIZE,
  131.     WQOMaxLength  = SQL_MAX_LENGTH,
  132.     WQOConcurrency = SQL_CONCURRENCY,
  133.     WQORetrieveData = SQL_RETRIEVE_DATA,
  134.     WQOUseBookmarks = SQL_USE_BOOKMARKS,
  135.     WQOKeysetSize = SQL_KEYSET_SIZE,
  136.     WQOMaxRows = SQL_MAX_ROWS,
  137.     WQOQueryTimeout = SQL_QUERY_TIMEOUT,
  138.  
  139.     // These are our own...
  140.  
  141.     WQOFirstNonODBC = 65536,
  142.  
  143.     WQOAutoPrepare,
  144.     WQOBindPolicy,
  145.     WQOBindLimit,
  146.     WQOAlwaysFetchOptions,
  147.     WQOAlwaysFetchRowPosition,
  148.     WQOAlwaysMoveCursor,
  149. };
  150.  
  151. enum WStmtCompare {
  152.     WSMLike = 0,
  153.     WSMNotLike,
  154.     WSMEqual,
  155.     WSMNotEqual,
  156.     WSMLessThan,
  157.     WSMGreaterThan,
  158.     WSMLessThanEqual,
  159.     WSMGreaterThanEqual,
  160. };
  161.  
  162. enum WStmtCondition {
  163.     WSNAnd = 0,
  164.     WSNOr,
  165. };
  166.  
  167. //
  168. // State information
  169. //
  170.  
  171. #define WQDRSTATE_OPENED       0x01
  172. #define WQDRSTATE_PREPARED     0x02
  173. #define WQDRSTATE_NOTFETCHED   0x04
  174. #define WQDRSTATE_NOTBOUND     0x08
  175. #define WQDRSTATE_NOTALLOCATED 0x10
  176. #define WQDRSTATE_NOTDATAOPEN  0x20
  177.  
  178. enum WODBCStmtHandle { NULLHSTMT = 0, LASTHSTMT = LAST_32BIT };
  179.  
  180. //
  181. // WICursorProxy
  182. //
  183.  
  184. class WQueryICursor;
  185.  
  186. class WCMCLASS WICursorProxyBase : public WReferenceObject {
  187.  
  188.     WDeclareSubclass( WICursorProxyBase, WReferenceObject );
  189.  
  190.     protected:
  191.         WICursorProxyBase( const WICursorProxyBase & ref );
  192.         WICursorProxyBase& operator=( const WICursorProxyBase & ref );
  193.  
  194.     protected:
  195.         WICursorProxyBase();
  196.  
  197.     public:
  198.         virtual ~WICursorProxyBase();
  199.  
  200.         virtual WBool DetachQuery( WQuery * ) = 0;
  201. };
  202.  
  203. //
  204. // WQuery -- Represents the results of a SQL statement.
  205. //
  206.  
  207. class WCMCLASS WQuery : public WDataSource {
  208.  
  209.     WDeclareSubclass( WQuery, WDataSource );
  210.  
  211.     public:
  212.  
  213.         WQuery();
  214.  
  215.         virtual ~WQuery();
  216.  
  217.  
  218.  
  219.         /***************************************************************
  220.          * Properties
  221.          ***************************************************************/
  222.  
  223.         // AlwaysFetchOptions
  224.         //
  225.         //    If TRUE, the query object always asks the database for
  226.         //    the state of a particular option.  If FALSE it uses the
  227.         //    value from its own cache.  If options are being set directly
  228.         //    by bypassing the query object you should set this to TRUE.
  229.         //    FALSE by default.
  230.  
  231.         virtual WBool GetAlwaysFetchOptions() const;
  232.         virtual WBool SetAlwaysFetchOptions( WBool always );
  233.  
  234.         // AlwaysFetchRowPosition
  235.         //
  236.         //    If TRUE, the query object always asks the database for
  237.         //    the current row position after each fetch.  Otherwise
  238.         //    the query object maintains its own count, which may not
  239.         //    be accurate if bookmarks are being used.  Because this
  240.         //    adds overhead, it is FALSE by default.  Also, not all
  241.         //    database drivers support this capability.
  242.  
  243.         virtual WBool GetAlwaysFetchRowPosition() const;
  244.         virtual WBool SetAlwaysFetchRowPosition( WBool always );
  245.  
  246.         // AlwaysMoveCursor
  247.         //
  248.         //    If TRUE, the query object always notifies the database
  249.         //    whenever the cursor is moved within the current rowset.
  250.         //    If FALSE, the database is only notified when necessary
  251.         //    (to get BLOB data, for example).  Default is FALSE.
  252.  
  253.         virtual WBool GetAlwaysMoveCursor() const;
  254.         virtual WBool SetAlwaysMoveCursor( WBool always );
  255.  
  256.         // AutoPrepare
  257.         //
  258.         //    If TRUE, the Prepare method will be called automatically
  259.         //    the first time a SQL statement is opened.
  260.  
  261.         virtual WBool GetAutoPrepare() const;
  262.         virtual WBool SetAutoPrepare( WBool on );
  263.  
  264.         // BindPolicy
  265.         //
  266.         //    The bind policy for default column binding.
  267.  
  268.         virtual WQueryBindPolicy GetBindPolicy() const;
  269.         virtual WBool            SetBindPolicy( WQueryBindPolicy policy );
  270.  
  271.         // BindLimit
  272.         //
  273.         //    The maximum size which a character or binary column can be
  274.         //    to be bindable.  A value of 0 means no limits.
  275.  
  276.         virtual WULong GetBindLimit() const;
  277.         virtual WBool  SetBindLimit( WULong limit );
  278.  
  279.         // ConcurrencyLevel
  280.         //
  281.         //    The concurrency level for the query. Can only be set
  282.         //    if the query is not open.  The default is read-only.
  283.  
  284.         virtual WQueryConcurrencyLevel GetConcurrencyLevel() const;
  285.         virtual WBool                  SetConcurrencyLevel( WQueryConcurrencyLevel l );
  286.  
  287.         // CurrentOffset
  288.         //
  289.         //    Returns the offset of the current row within the rowset
  290.         //    buffer, a value from 0 to RowsetSize-1.
  291.  
  292.         virtual WLong GetCurrentOffset() const;
  293.  
  294.         // CursorName
  295.         //
  296.         //    The name of the cursor.  If none is specified,
  297.         //    it is generated automatically.
  298.  
  299.         virtual WString GetCursorName() const;
  300.         virtual WBool   SetCursorName( const WString & str );
  301.  
  302.         // CursorType
  303.         //
  304.         //    Return the cursor type.
  305.  
  306.         virtual WQueryCursorType GetCursorType() const;
  307.         virtual WBool            SetCursorType( WQueryCursorType type );
  308.  
  309.         // DisplayErrorDialog
  310.         //
  311.         //    When an error occurs, display a dialog describing the
  312.         //    error.  TRUE by default.
  313.  
  314.         virtual WBool GetDisplayErrorDialog() const;
  315.         virtual WBool SetDisplayErrorDialog( WBool display );
  316.  
  317.         // DisplayWarningDialog
  318.         //
  319.         //    When a warning occurs, display a dialog describing the
  320.         //    warning.  FALSE by default.
  321.  
  322.         virtual WBool GetDisplayWarningDialog() const;
  323.         virtual WBool SetDisplayWarningDialog( WBool display );
  324.  
  325.         // DriverPacksRows
  326.         //
  327.         //    Set to true if the underlying query driver packs inserted and
  328.         //    deleted rows.
  329.  
  330.         virtual WBool GetDriverPacksRows() const;
  331.         virtual WBool SetDriverPacksRows( WBool packsRows );
  332.  
  333.         // ErrorList
  334.         //
  335.         //    Returns the list of errors from the last operation.
  336.  
  337.         virtual WDataErrorArray GetErrorList() const;
  338.  
  339.         // FetchedRows
  340.         //
  341.         //    Returns the number of rows that were actually fetched.
  342.         //    Can be 0 (none) up to RowsetSize.
  343.  
  344.         virtual WLong GetFetchedRows() const;
  345.  
  346.         // Handle
  347.         //
  348.         //    Returns a handle, which is driver-specific.  After a
  349.         //    valid Create, should be non-zero.  After a Destroy,
  350.         //    should be zero.
  351.  
  352.         virtual WDWord GetHandle() const;
  353.         virtual WBool  SetHandle( WDWord handle );
  354.  
  355.         // KeysetSize
  356.         //
  357.         //    Determines the keyset size for keyset-driven cursors.
  358.         //    The default is 0, which means a fully keyset-driven
  359.         //    cursor, otherwise the cursor is mixed.  The keyset
  360.         //    size must be greater than the rowset size.
  361.  
  362.         virtual WLong GetKeysetSize() const;
  363.         virtual WBool SetKeysetSize( WLong size );
  364.  
  365.         // LongColumnBindSize
  366.         //
  367.         //    Sets the amount of memory to allocate for LONGVARCHAR
  368.         //    and LONGVARBINARY columns if a buffer size of 0 is
  369.         //    passed to BindColumn.  The default is 0, which means
  370.         //    that long columns are never bound.  Any other value is
  371.         //    the maximum amount of data that can be set or gotten
  372.         //    from the column, up to the BindLimit property.
  373.  
  374.         virtual WULong GetLongColumnBindSize() const;
  375.         virtual WBool  SetLongColumnBindSize( WULong size );
  376.  
  377.         // MaxLength
  378.         //
  379.         //    The maximum of binary or character data that can be
  380.         //    fetched in a single call.  The default value is 0,
  381.         //    which means return as much as possible.  The maximum
  382.         //    value for this property is 64K (=65536 bytes).  Note
  383.         //    that the MaxLength property affects the amount of
  384.         //    data returned by GetRawData.
  385.  
  386.         virtual WULong GetMaxLength() const;
  387.         virtual WBool  SetMaxLength( WULong maxLength );
  388.  
  389.         // MaxRows
  390.         //
  391.         //    The maximum number of rows to return in a result set.
  392.         //    If 0, all rows are returned.
  393.  
  394.         virtual WULong GetMaxRows() const;
  395.         virtual WBool  SetMaxRows( WULong maxRows );
  396.  
  397.         // Parameter
  398.         //
  399.         //    Defines a parameter value for use in parameterized
  400.         //    queries.  Setting a parameter will implicitly cause
  401.         //    the BindParameter method to be called.  Parameters
  402.         //    are numbered starting at 1.  Can optionally declare
  403.         //    whether the parameter should be input, input/output
  404.         //    or output only.  
  405.  
  406.         virtual WDataValue GetParameter( WShort paramNo ) const;
  407.         virtual WBool      SetParameter( WShort paramNo,
  408.                                          const WDataValue & val,
  409.                                          WColumnDataType sqlType=SQL_TYPE_NULL,
  410.                                          WQueryParameterType type=WQPTInput,
  411.                                          SDWORD maxSize=0 );
  412.  
  413.         // Prepared
  414.         //
  415.         //    Returns TRUE if the statement has been prepared for execution.
  416.  
  417.         virtual WBool GetPrepared() const;
  418.  
  419.         // QueryObject
  420.         //
  421.         //    Returns the "real" query object that is being used
  422.         //    to communicate with the database, which may or
  423.         //    may not == this.
  424.  
  425.         WQuery *GetQueryObject() const
  426.                   { return _queryDriver ? _queryDriver : (WQuery *) this; }
  427.  
  428.         // QueryTimeout
  429.         //
  430.         //    Defines the time in seconds to wait for a statement
  431.         //    to execute.  The default is 0, which means wait
  432.         //    indefinitely.
  433.  
  434.         virtual WULong GetQueryTimeout() const;
  435.         virtual WBool  SetQueryTimeout( WULong seconds );
  436.  
  437.         // RetrieveData
  438.         //
  439.         //    If FALSE, no data is actually retrieved when a fetch
  440.         //    is done.  Use this to move around through the data
  441.         //    to get bookmarks, etc.  Default is TRUE.  Can only be
  442.         //    set at run time.
  443.  
  444.         virtual WBool GetRetrieveData() const;
  445.         virtual WBool SetRetrieveData( WBool ret );
  446.  
  447.         // RowsetSize
  448.         //
  449.         //    The maximum number of rows that are buffered locally by the
  450.         //    query object.  Setting the rowset size automatically
  451.         //    unbinds any bound columns.
  452.  
  453.         virtual WLong  GetRowsetSize() const;
  454.         virtual WBool  SetRowsetSize( WLong size );
  455.  
  456.         // RowsetStatus
  457.         //
  458.         //    Returns the status of a row in the current rowset.  Rows
  459.         //    are numbered from 1 to n (where n = GetRowsetSize() ).
  460.  
  461.         virtual UWORD GetRowsetStatus( WLong row=1 ) const;
  462.  
  463.         // SQL
  464.         //
  465.         //    Stores the SQL statement to be executed.  Setting a new
  466.         //    statement closes the current query (if open).
  467.  
  468.         virtual WString GetSQL() const;
  469.         virtual WBool   SetSQL( const WString & str );
  470.  
  471.         // State
  472.         //
  473.         //    Return the current state of the query.
  474.  
  475.         virtual WDWord GetState() const;
  476.  
  477.         // TraceToLog
  478.         //
  479.         //    In debug mode, if TRUE traces important actions
  480.         //    to the debug log.  Has no effect for release mode
  481.         //    applications.  (This is not the same as the ODBC
  482.         //    trace log.)
  483.  
  484.         virtual WBool GetTraceToLog() const;
  485.         virtual WBool SetTraceToLog( WBool on );
  486.  
  487.         // TransactionObject
  488.         //
  489.         //    The transaction object to use.
  490.  
  491.         virtual WTransaction *GetTransactionObject() const;
  492.         virtual WBool         SetTransactionObject( WTransaction *obj );
  493.  
  494.         // UpdatePolicy
  495.         //
  496.         //    The update policy for the type of action to take when
  497.         //    updating.
  498.  
  499.         virtual WQueryUpdatePolicy GetUpdatePolicy() const;
  500.         virtual WBool              SetUpdatePolicy( WQueryUpdatePolicy policy );
  501.  
  502.         // UseBookmarks
  503.         //
  504.         //    If TRUE, bookmarks can be used.  Must be set before
  505.         //    the cursor is opened.  Default is FALSE.
  506.  
  507.         virtual WBool GetUseBookmarks() const;
  508.         virtual WBool SetUseBookmarks( WBool use );
  509.  
  510.         // UseDefaultBindTypes
  511.         //
  512.         //    If TRUE, BindColumn is called with SQL_C_DEFAULT when
  513.         //    a column is bound by a data target.  If FALSE, the
  514.         //    type suggested by the data target is used instead.  This
  515.         //    controls who does the conversion between data types: the
  516.         //    database driver or the WDataValue class.  Calls to
  517.         //    BindColumn by the user are not affected.
  518.  
  519.         virtual WBool GetUseDefaultBindTypes() const;
  520.         virtual WBool SetUseDefaultBindTypes( WBool use );
  521.  
  522.         /***************************************************************
  523.          * Methods
  524.          ***************************************************************/
  525.  
  526.         // AddSearchParameter
  527.         //
  528.         //    Add a search parameter to the current query. The query must
  529.         //    be open if you want to specify a column index instead of a
  530.         //    column name.
  531.  
  532.         virtual WBool AddSearchParameter( const WString & columnName, WDataValue value,
  533.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  534.         virtual WBool AddSearchParameter( WShort columnIndex, WDataValue value,
  535.                       WStmtCondition=WSNAnd,WStmtCompare compare=WSMLike);
  536.  
  537.         // BindColumn
  538.         //
  539.         //    Bind a column in the current query, which must be open.
  540.         //    By default it will allocate internal storage for the binding
  541.         //    based on the type of the column and the rowset size as
  542.         //    well as an array for storing the actual length of retrieved
  543.         //    data.  The user can provide alternates for any of these.
  544.  
  545.         virtual WBool BindColumn( WShort column, WNativeDataType type=SQL_C_DEFAULT,
  546.                                   void *arrayStart=NULL, SDWORD elementSize=0,
  547.                                   SDWORD *lengthArray=NULL );
  548.  
  549.         // BindParameter
  550.         //
  551.         //    Bind a parameter for execution with the next query.
  552.         //    In most cases you call SetParameter instead of this method,
  553.         //    and the binding will be done automatically for you.
  554.         //    This method provides low-level access to the binding
  555.         //    process.  Parameters start at 1.
  556.  
  557.         virtual WBool BindParameter( WShort paramNo, WQueryParameterType type,
  558.                                      WNativeDataType cType,
  559.                                      WColumnDataType sqlType,
  560.                                      UDWORD precision, SWORD scale,
  561.                                      void *dataBuffer, SDWORD maxSize,
  562.                                      SDWORD *actualLength );
  563.  
  564.         // BoundControlSearch
  565.         //    Opens a new result set given the search parameters from
  566.         //    changed bound controls.
  567.  
  568.         virtual WBool BoundControlSearch( WStmtCondition condition=WSNAnd,
  569.                                  WStmtCompare compare=WSMLike);
  570.         // Clone
  571.         //
  572.         //    Allocates and returns a "clone" of the query object.
  573.         //    The clone is a semi-independent query object needed
  574.         //    for use with complex OCX data binding.
  575.  
  576.         virtual WQuery *Clone();
  577.  
  578.         // Close
  579.         //
  580.         //    Close the current query, if any.
  581.  
  582.         virtual WBool Close( WBool discardResults=TRUE,
  583.                              WBool isRequery=FALSE );
  584.  
  585.         // Create
  586.         //
  587.         //    Calls SetTransactionObject and then checks to see if
  588.         //    the transaction object is ready for use.
  589.  
  590.         virtual WBool Create( WTransaction *trans );
  591.  
  592.         // DeleteSearchParameters
  593.         //
  594.         //    Deletes the search parameters added to the current query
  595.  
  596.         virtual WBool DeleteSearchParameters();
  597.  
  598.         // Destroy
  599.  
  600.         virtual WBool Destroy();
  601.  
  602.         // Execute
  603.         //
  604.         //    Execute a non-select SQL statement.  Closes the current
  605.         //    query, if any.  If an empty or null string is passed in, simply
  606.         //    executes the string in the SQL property.
  607.  
  608.         virtual WBool Execute( const WString & stmt=WString::GetNullString() );
  609.  
  610.         // Fetch
  611.         //
  612.         //    Fetch a rowset of data from the database.
  613.  
  614.         virtual WBool Fetch( WLong row, WBool notifyTargets=TRUE,
  615.                              WDSMoveType type=WDSMoveAbsolute,
  616.                              WBool triggerEvents=TRUE );
  617.  
  618.         // FetchBookmark
  619.         //
  620.         //    Fetch to a bookmark.
  621.  
  622.         WBool FetchBookmark( WDWord bookmark, WBool notify=TRUE,
  623.                              WBool triggerEvents=TRUE );
  624.  
  625.         // FetchErrors
  626.         //
  627.         //    Clear the current error list and fetch errors from the
  628.         //    driver for later retrieval with
  629.         //    GetErrorList.  Note that this function is called automatically
  630.         //    by most of the other methods, so you should only call it
  631.         //    after directly invoking an operation on the driver.
  632.         //    You pass in the return code and function code of the
  633.         //    last operation.  Returns TRUE if messages were fetched
  634.         //    from the driver.
  635.  
  636.         virtual WBool FetchErrors( WLong errorCode, WLong funcCode );
  637.  
  638.         // FetchFirst
  639.         //
  640.         //    Fetch to the first row.
  641.  
  642.         WBool FetchFirst( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  643.  
  644.         // FetchLast
  645.         //
  646.         //    Fetch to the last row.
  647.  
  648.         WBool FetchLast( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  649.  
  650.         // FetchNext
  651.         //
  652.         //    Fetch to the next row.
  653.  
  654.         WBool FetchNext( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  655.  
  656.         // FetchPrevious
  657.         //
  658.         //    Fetch to the previous row.
  659.  
  660.         WBool FetchPrevious( WBool notifyTargets=TRUE, WBool triggerEvents=TRUE );
  661.  
  662.         // FetchRelative
  663.         //
  664.         //    Fetch to a relative row.
  665.  
  666.         WBool FetchRelative( WLong offset, WBool notifyTargets=TRUE,
  667.                              WBool triggerEvents=TRUE );
  668.  
  669.         // FlushUnboundValues
  670.         //
  671.         //    Flushes the unbound value cache.  When data is fetched from
  672.         //    an unbound column, a copy is kept in memory.  This method
  673.         //    frees any copies currently in memory.  It is called implicitly
  674.         //    whenever a move occurs.
  675.  
  676.         virtual WBool FlushUnboundValues();
  677.  
  678.         // MarkColumnForUpdate
  679.         //
  680.         //    After entering add/edit mode, call this method before
  681.         //    calling Update if you wish to manually set the length
  682.         //    field of a bound column so that it will be updated.
  683.         //    Otherwise the length field is set to SQL_IGNORE unless
  684.         //    you call SetValue for that column.  Returns success.
  685.  
  686.         virtual WBool MarkColumnForUpdate( WShort column, WBool mark );
  687.  
  688.         // Open
  689.         //
  690.         //    Execute the SQL statement and open the result set for
  691.         //    processing.
  692.  
  693.         virtual WBool Open( WBool executeStatement=TRUE,
  694.                             WBool isRequery=FALSE );
  695.  
  696.         // Prepare
  697.         //
  698.         //    Prepare the SQL statement for execution.  Call this
  699.         //    if you intend to execute the same SQL statement multiple
  700.         //    times.  Closes any open query.
  701.  
  702.         virtual WBool Prepare();
  703.  
  704.         // QueryColumnBinding
  705.         //
  706.         //    Return information on how a column is bound.  Returns TRUE
  707.         //    if the column is bound, FALSE otherwise. Can optionally
  708.         //    get pointer to data area, element size, etc.
  709.  
  710.         virtual WBool QueryColumnBinding( WShort column,
  711.                                           WNativeDataType *boundAs=NULL,
  712.                                           void **arrayStart=NULL,
  713.                                           SDWORD *elementSize=NULL,
  714.                                           SDWORD **lengthArray=NULL );
  715.  
  716.         // Reference
  717.         //
  718.         //    Bump up the reference count.  Only useful for clones.
  719.         //    Returns the new reference count.
  720.  
  721.         virtual WLong Reference();
  722.  
  723.         // ResetSearch
  724.         //
  725.         //    Resets the search parameters. This is called before using
  726.         //    search.
  727.  
  728.         virtual WBool ResetSearch();
  729.  
  730.         // Resubmit
  731.         //
  732.         //    Re-executes the SQL statement that was last set using
  733.         //    the SQL property.  This is equivalent to calling Close
  734.         //    and then Open, but is a bit more efficient.
  735.  
  736.         virtual WBool Resubmit( WBool executeStatement=TRUE,
  737.                                 WBool closeCursor=TRUE );
  738.  
  739.         // Search
  740.         //
  741.         //    Opens a new result set given the current query and the added
  742.         //    search parameters. This closes the current query and opens
  743.         //    a new query based on the added search parameters.
  744.         //
  745.  
  746.         virtual WBool Search();
  747.  
  748.         // Search
  749.         //
  750.         //    This form of search is used if only one parameter is to be
  751.         //    added to the current query.  This closes the current query
  752.         //    and opens a new query based on the added parameter.
  753.         //
  754.         virtual WBool Search( WShort columnIndex, WDataValue value,
  755.                       WStmtCondition cond=WSNAnd,WStmtCompare compare=WSMLike);
  756.         virtual WBool Search( const WString & columnName, WDataValue value,
  757.                       WStmtCondition cond=WSNAnd,WStmtCompare compare=WSMLike);
  758.  
  759.         // UnbindColumn
  760.         //
  761.         //    Undo the binding of a column.  Pass a negative value
  762.         //    to unbind all bound columns.
  763.  
  764.         virtual WBool UnbindColumn( WShort column );
  765.  
  766.         // UnbindParameter
  767.         //
  768.         //    Undo the binding of a parameter.  Pass a negative value
  769.         //    to unbind all parameters.
  770.  
  771.         virtual WBool UnbindParameter( WShort paramNo );
  772.  
  773.         // Unreference
  774.         //
  775.         //    Decrements the reference count.  Only useful for clones.
  776.         //    Returns the new reference count.
  777.  
  778.         virtual WLong Unreference();
  779.  
  780.         /***************************************************************
  781.          * Item Properties
  782.          ***************************************************************/
  783.  
  784.         // NumericOption
  785.         //
  786.         //    Set/get a query option.
  787.  
  788.         virtual WLong GetNumericOption( WULong id, WBool *ok=NULL ) const;
  789.         virtual WBool SetNumericOption( WULong id, WLong value );
  790.  
  791.         // OptionID
  792.         //
  793.         //    Return the ID associated with an option string.  Can also
  794.         //    return whether the option is numeric or string.  A value of
  795.         //    zero means an invalid option.
  796.  
  797.         virtual WULong GetOptionID( const WString & str,
  798.                                     WBool *isString=NULL ) const;
  799.  
  800.         // StringOption
  801.         //
  802.         //    Set/get a query option.
  803.  
  804.         virtual WString GetStringOption( WULong id ) const;
  805.         virtual WBool   SetStringOption( WULong id, const WString & str );
  806.  
  807.         /***************************************************************
  808.          * Other
  809.          ***************************************************************/
  810.  
  811.         virtual WICursorProxyBase *GetICursorProxy() const;
  812.         virtual WBool              SetICursorProxy( WICursorProxyBase *p );
  813.  
  814.         /***************************************************************
  815.          * Overrides
  816.          ***************************************************************/
  817.  
  818.         WBool AddTarget( WDataTarget *target );
  819.  
  820.         WBool GetAutoEdit() const;
  821.         WBool SetAutoEdit( WBool autoEdit );
  822.  
  823.         WBool GetAutoRefresh() const;
  824.         WBool SetAutoRefresh( WBool autoRefresh );
  825.  
  826.         WBool GetBOF() const;
  827.  
  828.         WDWord GetBookmark() const;
  829.  
  830.         WShort GetColumnCount() const;
  831.  
  832.         const WDataColumn & GetColumn( WShort index ) const;
  833.         const WDataColumn & GetColumn( const WString & name ) const;
  834.  
  835.         WShort GetColumnIndex( const WString & str ) const;
  836.  
  837.         WLong GetCurrentRow() const;
  838.  
  839.         WDSEditMode GetEditMode() const;
  840.  
  841.         WBool GetEmpty() const;
  842.  
  843.         WBool GetEOF() const;
  844.  
  845.         WLong GetErrorCode( WLong *apiCode=NULL ) const;
  846.  
  847.         WBool GetForwardOnly() const;
  848.  
  849.         WBool GetNull() const;
  850.  
  851.         WBool GetOpened() const;
  852.  
  853.         WBool GetRawData( WShort index, WNativeDataType type,
  854.                           void *buffer, WLong bufferSize=0,
  855.                           WLong *bytesRemaining=NULL ) const;
  856.  
  857.         WBool GetReadOnly() const;
  858.  
  859.         WBool GetRowTargetChanged() const;
  860.         WBool SetRowTargetChanged( WBool changed );
  861.  
  862.         WBool GetRowChanged() const;
  863.         WBool SetRowChanged( WBool changed );
  864.  
  865.         WLong GetRowCount( WBool force=TRUE ) const;
  866.  
  867.         WBool GetTargetsEnabled() const;
  868.         WBool SetTargetsEnabled( WBool enabled );
  869.  
  870.         WBool GetAlwaysReadWriteTargets() const;
  871.         WBool SetAlwaysReadWriteTargets( WBool enabled );
  872.  
  873.         WBool GetThreadSafe() const;
  874.         WBool SetThreadSafe( WBool safe );
  875.  
  876.         WBool Add( WBool copyValues=FALSE, WBool append=FALSE,
  877.                    WBool copyIntoBuffer=FALSE );
  878.  
  879.         WBool CancelUpdate( WBool notifyTargets=TRUE );
  880.  
  881.         WBool ClearTargets();
  882.  
  883.         WBool Delete( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  884.  
  885.         WBool Edit();
  886.  
  887.         WBool MoreResults();
  888.  
  889.         WBool Move( WLong row, WBool notifyTargets=TRUE,
  890.                     WDSMoveType type=WDSMoveAbsolute, WBool trigger=TRUE );
  891.  
  892.         WBool Refresh();
  893.  
  894.         WBool RefreshTargets( WBool multiRow=FALSE );
  895.  
  896.         WBool RestoreState( const WDataSourceState state, WBool restore=TRUE );
  897.  
  898.         WBool SaveState( WDataSourceState & state );
  899.  
  900.         WBool SearchUsingTargets() { return BoundControlSearch(); }
  901.  
  902.         WBool ThreadLock( WBool wait=TRUE, WDWord timeout=0xFFFFFFFF );
  903.  
  904.         WBool ThreadUnlock();
  905.  
  906.         WBool Update( WBool triggerEvent=TRUE, WBool notifyTargets=TRUE );
  907.  
  908.         WDataValue GetValue( WShort index, WNativeDataType type=SQL_C_DEFAULT ) const;
  909.         WBool      SetValue( WShort index, const WDataValue & val );
  910.  
  911.         /***************************************************************
  912.          * Deprecated
  913.          ***************************************************************/
  914.  
  915.         virtual WBool GetErrorInfo( WString *errorMessage,
  916.                                     WString *state=NULL,
  917.                                     WLong *nativeErrorCode=NULL ) const;
  918.  
  919.         /***************************************************************
  920.          * Internal
  921.          ***************************************************************/
  922.  
  923.     public:
  924.  
  925.         virtual WBool CountRows( WBool ensureValid=TRUE );
  926.         virtual WBool CopySettingsToDriver( WBool assumeDefaults );
  927.         virtual WBool TransactionEvent( WEventID id, WEventData *data );
  928.         virtual WBool AddClone( WQuery *clone );
  929.         virtual WBool RemoveClone( WQuery *clone );
  930.  
  931.     protected:
  932.  
  933.         virtual WBool LateBindTarget( WQuery *query, WDataTarget *target );
  934.         virtual void  EventNotice( WEventID id, WEventNotice type );
  935.  
  936.         // These are called when the transaction object connects or
  937.         // disconnects from a database.  The Connect method gets called
  938.         // before the Connect event, the Disconnect event gets called
  939.         // before the method.
  940.  
  941.         virtual WBool Connect( WEventData *data );
  942.         virtual WBool Disconnect( WEventData *data );
  943.  
  944.         WTransaction  *_transaction;
  945.         WQuery        *_queryDriver;
  946. };
  947.  
  948. class WCMCLASS WQueryFactory : public WObject {
  949.  
  950.     protected:
  951.  
  952.         WQueryFactory();
  953.  
  954.         ~WQueryFactory();
  955.  
  956.     public:
  957.  
  958.         static WQueryFactory *GetFactoryObject();
  959.  
  960.         static WQuery *Allocate( const WString & dbmsName, WQuery *proxy );
  961.  
  962.         static void Register( WQuery * WCMDEF (*func)( const WString &, WQuery * ) );
  963.         static void Deregister( WQuery * WCMDEF (*func)( const WString &, WQuery * ) );
  964.  
  965.     protected:
  966.         wllist_header                list;
  967.  
  968.     private:
  969.         static WQueryFactory *_theObject;
  970. };
  971.  
  972. #endif
  973.